﻿using System.Reflection;

namespace UPKAndUDKUnpackTools.Tools;

public static class ToolExporter
{
    /// <summary>
    ///     从嵌入资源中导出指定的可执行工具文件。
    /// </summary>
    /// <param name="exeNames">可执行文件名称数组。</param>
    public static bool ExportToolsExe(string[] exeNames)
    {
        var currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
        foreach (var exe in exeNames)
        {
            var outputPath = Path.Combine(currentDirectory, exe);
            using var stream = Assembly.GetExecutingAssembly()
                .GetManifestResourceStream($"UPKAndUDKUnpackTools.Resources.{exe}");
            if (stream == null)
            {
                Console.WriteLine($"资源 {exe} 未找到。");
                return false;
            }

            using var fileStream = new FileStream(outputPath, FileMode.Create);
            stream.CopyTo(fileStream);
        }
        return  true;
        
    }
}